from a3mall_gwc.ApiBase import ApiBase
import pytest

class Test_a3mall2():
    token = None
    uid=None
    @pytest.fixture(scope='session')
    def api(self):
        return ApiBase()

    # 登录
    def test_login(self,api):
        login_data = {"username":"18836066873","password":"12345Aa"}
        login = api.post(
            path="/api/public/login",
            json=login_data
        )
        print(login.json())
        Test_a3mall2.token = 'Bearer ' + login.json()['data']['token']

    # 团购列表
    def test_tg(self,api):
        tou = {"auth-token": Test_a3mall2.token}
        tg = api.get(
            path="/api/regiment?page=1&type=0&sort=1",
            headers=tou
        )
        print(tg.json())

    # 团购商品详情
    def test_tg_xq(self,api):
        tou = {"auth-token":Test_a3mall2.token}
        xq=api.get(
            path='/api/regiment/view?id=2',
            headers=tou
        )
        print(xq.json())
        Test_a3mall2.uid2 = xq.json()['data']['goods']['id']

    # 购买团购商品
    def test_tg_dd(self,api):
        tou = {"auth-token":Test_a3mall2.token}
        dd=api.get(
            path=f"/api/order/confirm?id={Test_a3mall2.uid}&type=regiment&sku_id=&num=1&shipping_type=1&address_id=58",
            headers=tou
        )
        print(dd.json())

    # 支付
    def test_tg_zf(self,api):
        tou = {"auth-token":Test_a3mall2.token}
        ti = {"id":"2","type":"regiment","address_id":58,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=2&sku_id=&num=1&type=regiment","sku_id":"","num":"1"}
        zf=api.post(
            path="/api/order/create",
            headers=tou,
            json=ti
        )
        print(zf.json())
